<?php
    class AttachPaymentJar extends CActiveRecord
    {
         public static function model($className = __CLASS__) {
            return parent::model ( $className );
        }

        public function tableName() {                  
            return 'c_attach_payment_jar';
        }
        public function InsertFileJar($username,$userId,$filename,$serviceNumber,$mo,$price,$timeTrial,$countTrial,$timeSms,$countSms,$isSms,$isPriceDown,$status,$create_date){
            $sql = "INSERT INTO c_attach_payment_jar SET
            username=:username
            , filename=:filename
            , serviceNumber=:serviceNumber
            , mo=:mo
            , price=:price
            , timeTrial=:timeTrial
            , countTrial=:countTrial
            , timeSms=:timeSms
            , countSms=:countSms
            , isSms=:isSms
            , isPriceDown=:isPriceDown
            , status=:status
            , create_date=:create_date
            , userId=:userId
            ";
            $command = Yii::app()->db->createCommand($sql);
            $command->bindValue(":username",$username , PDO::PARAM_STR);
            $command->bindValue(":filename",$filename , PDO::PARAM_STR);
            $command->bindValue(":serviceNumber",$serviceNumber , PDO::PARAM_STR);
            $command->bindValue(":mo",$mo , PDO::PARAM_STR);
            $command->bindValue(":price", $price, PDO::PARAM_INT);
            $command->bindValue(":timeTrial", $timeTrial, PDO::PARAM_INT);
            $command->bindValue(":countTrial", $countTrial, PDO::PARAM_INT);
            $command->bindValue(":timeSms", $timeSms, PDO::PARAM_INT);
            $command->bindValue(":countSms", $countSms, PDO::PARAM_INT);
            $command->bindValue(":isSms", $isSms, PDO::PARAM_INT);
            $command->bindValue(":isPriceDown", $isPriceDown, PDO::PARAM_INT);
            $command->bindValue(":status", $status, PDO::PARAM_INT);
            $command->bindValue(":create_date",$create_date , PDO::PARAM_INT);
            $command->bindValue(":userId",$userId , PDO::PARAM_INT); 
            $result = $command->execute();

            $jarId = Yii::app()->db->getLastInsertID();
            return $jarId;        
        }
        public function getDataByUserIdJar($userId,$currentPage,$numberRecordPerPage){
            $startRecord = ($currentPage - 1) * $numberRecordPerPage;
            $sql = "SELECT * FROM c_attach_payment_jar WHERE userId=" . $userId." ORDER BY create_date DESC LIMIT " . $startRecord . ", " . $numberRecordPerPage;
            $command = Yii::app()->db->createCommand($sql);
            $rows = $command->queryAll();  
            return $rows;
        }
        public function getDataByGameIdJar($id){
            $sql = "SELECT * FROM c_attach_payment_jar WHERE id=" . $id;
            $command = Yii::app()->db->createCommand($sql);
            $rows = $command->queryRow();  
            return $rows;
        }
        public function getTotalGameKHJar($userId)
        {
            $sql = "SELECT count(id) FROM c_attach_payment_jar WHERE  userId=  ".$userId;
            $command = Yii::app()->db->createCommand($sql);
            $rows = $command->queryRow();        
            return $rows["count(id)"];
        }
    } 
?>              
